package com.tmt.im.manager.controller.api;


import com.tmt.springboot.common.restful.ResultWrapper;
import com.tmt.im.manager.controller.vo.SlideQueryRequest;
import com.tmt.im.manager.controller.vo.SlideQuerySystemNotifyResponse;
import com.tmt.im.manager.controller.vo.SystemNotifyVo;
import com.tmt.im.manager.controller.vo.SystemNotifyVoEx;
import com.tmt.im.manager.service.SystemNotifyService;
import com.tmt.springboot.common.restful.ExecuteResult;
import com.tmt.springboot.common.restful.IExecuteResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.scheduling.annotation.Async;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.concurrent.CompletableFuture;

/**
 * 客服相关接口
 *
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/20 9:59
 * @Version 1.0
 **/
@Async("asyncTaskExecutor")
@Tag(name = "系统通知相关接口", description = "系统通知相关接口")
@RestController
@RequestMapping("${api-url-prefix}/notify")
public class SystemNotifyController {

    private final SystemNotifyService notifyService;

    public SystemNotifyController(SystemNotifyService notifyService) {
        this.notifyService = notifyService;
    }

    @Operation(summary = "创建系统通知",
            description = "创建系统通知接口",
            operationId = "createSystemNotify",
            parameters = {
                    @Parameter(name = "vo", description = "要创建的系统通知信息对象", required = true)
            })
    @PostMapping("/create")
    public CompletableFuture<IExecuteResult<SystemNotifyVoEx>> createSystemNotify(@RequestBody @Validated SystemNotifyVo vo, Principal principal) {
        IExecuteResult<SystemNotifyVoEx> result = notifyService.createSystemNotify(vo, principal);
        return CompletableFuture.completedFuture(result);
    }

    @Operation(summary = "修改系统通知",
            description = "修改系统通知接口",
            operationId = "updateSystemNotify",
            parameters = {
                    @Parameter(name = "vo", description = "要更新的系统通知对象", required = true)
            })
    @PostMapping("/update")
    public CompletableFuture<IExecuteResult<SystemNotifyVoEx>> updateSystemNotify(@RequestBody @Validated SystemNotifyVo vo, Principal principal) {
        if (vo.getId() == null) {
            return CompletableFuture.completedFuture(ExecuteResult.failure("系统通知ID不能为空", null));
        }
        IExecuteResult<SystemNotifyVoEx> result = notifyService.updateSystemNotify(vo, principal);
        return CompletableFuture.completedFuture(result);
    }

    @Operation(summary = "删除系统通知",
            description = "删除系统通知接口",
            operationId = "updateSystemNotify",
            parameters = {
                    @Parameter(name = "notifyId", description = "要删除的系统通知ID", required = true)
            })
    @PostMapping("/delete/{notifyId}")
    public CompletableFuture<IExecuteResult<ResultWrapper<Boolean>>> deleteSystemNotify(@PathVariable("notifyId") Long notifyId, Principal principal) {
        IExecuteResult<Boolean> result = notifyService.deleteSystemNotify(notifyId, principal);
        return CompletableFuture.completedFuture(ResultWrapper.from(result));
    }

    @Operation(summary = "滑动查询系统通知列表",
            description = "滑动查询系统通知列表接口",
            operationId = "slideQuerySystemNotifies",
            parameters = {
                    @Parameter(name = "request", description = "滑动查询参数", required = true)
            })
    @PostMapping("/slideQuery")
    public CompletableFuture<IExecuteResult<SlideQuerySystemNotifyResponse>> slideQuerySystemNotifies(@RequestBody @Validated SlideQueryRequest request, Principal principal) {
        IExecuteResult<SlideQuerySystemNotifyResponse> result = notifyService.slideQuerySystemNotifies(request, principal);
        return CompletableFuture.completedFuture(result);
    }

}
